#include "setBehavior.h"
#include "Character.h"
#include "Steering.h"


setBehavior::setBehavior(){
}

Steering* setBehavior::getSteering(){
  Steering *ret = new Steering();
  Steering* aux = NULL;
  for (int i = 0, n = set.size(); i < n;i++){
    cout << " n sB " << n << endl;
//  cout << " SET[i] es nulo " << (set[i] == NULL) << endl;
    aux = set[i]->getSteering();
  cout << "paso " << endl;
    ret->linear[0] +=aux->linear[0];
    ret->linear[1] +=aux->linear[1];
    ret->linear[2] +=aux->linear[2];
    ret->angular += aux->angular;
  }
  return ret;
}


void setBehavior::addBehavior(Behavior* b, Character* character, Character* target){
  b->SetTarget(target);
  b->SetCharacter(character);
  set.push_back(b);
}

void setBehavior::updateKinematicData(){
  for(int i=0, n=set.size(); i<n; i++){
    set[i]->updateKinematicData();
  }
}
/*
void setBehavior::SetTarget(Character *c){
  cout << "entro setTarget setBehavior " << endl;
  cout << "n = " << set[0] << endl;
  for(int i=0, n=set.size(); i<n; i++)
    set[i]->SetTarget(c);
  cout << "salio setTarget setBehavior " << endl;
}
*/

void setBehavior::SetTarget(Character*c){
  for (int i =0 , n = set.size() ; i < n; i++){
    set[i]->SetTarget(c);
  }
}

const Character* setBehavior::GetTarget(){
  return set[1]->GetTarget();
}

void setBehavior::SetCharacter(Character *c){
  for (int i =0 , n = set.size() ; i < n; i++){
    set[i]->SetCharacter(c);
  }
}



